var contextPath;
/*init jQuery datepicker*/
function initDatePicker(id, req) {
	var required = false;
	if (req != null) {
		required = req;
	}
	
	$("#" + id).datebox({  
		required:required  
		});
		
}

function initButton(id, callback) {
	$("#" + id).bind("click", callback);
}


function deleteRecord(formName, dataTable, key) {
	
	var rows = $('#' + dataTable).datagrid('getSelections');
	if (rows.length <= 0) {
		 $.messager.alert('信息','请选择一条记录！','info');
		 return;
	} else {
		$.messager.confirm('信息', '确定要删除这些记录？', function(r){
			if (r){
				var ids = [];
				for(var i=0;i<rows.length;i++){
					ids.push(rows[i][key]);
				}
				$("#" + formName + " #deleteId").val(ids.join(','));
				$("#" + formName).submit();
			}
		});
	}
}

function checkAmount(tempValue) {
	var regu = /^(\d+)(\.?)(\d{0,2})$/; 
	var re = new RegExp(regu); 
	if (!re.test(tempValue)) { 
		$.messager.alert('信息','请按以下格式输入金额!\n(###.##)或 (###)','info');
		return false;
	}
	
	return true;
}


function moneyForamt(str, cutsize) {
	if (cutsize == null) {
		cutsize = 3;
	}
	if (typeof str == "number") {
		str += "";
	}
	
	var decimal = "";
	var integer = str;
	if (str.indexOf(".") > 0) {
		decimal = str.substring(str.indexOf("."));
		integer = str.substring(0, str.indexOf("."));
	}
	
	var str_array = integer.split("");
	var size = str_array.length;
	if (size <= 3) {
		return str;
	}
	str_array = str_array.reverse();
	var temp_array = [];
	for ( var i = 0; i < size; i++) {
		var s = str_array[i];
		temp_array.push(s);
		if ((i + 1) % cutsize == 0) {
			temp_array.push(",");
		}
	}
	var res = temp_array.reverse().join("");
	res = res.replace(/^,/, "");
	return res + decimal;
}

Date.prototype.format = function(format) {
	var o = {
		"M+" : this.getMonth() + 1, // month
		"d+" : this.getDate(), // day
		"h+" : this.getHours(), // hour
		"m+" : this.getMinutes(), // minute
		"s+" : this.getSeconds(), // second
		"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
		"S" : this.getMilliseconds()
	// millisecond
	};

	if (/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + "")
				.substr(4 - RegExp.$1.length));
	}

	for ( var k in o) {
		if (new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
					: ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return format;
}; 


function popUpCallback(id, name, idValue, nameValue) {
	$('#'+id).val(idValue);
	$('#'+name).val(nameValue);
}